// api/family/recipe.ts
import { api } from '@/api/request'
import type { PageData, PageQuery } from '@/types'

// 食谱信息模型
export interface RecipeInfo {
    id: number
    name: string
    type: string  // 菜系类型: sichuan, cantonese, shandong, jiangsu, zhejiang, fujian, hunan, anhui
    difficulty: number  // 难度等级: 1-简单, 2-中等, 3-困难
    cooking_time: number  // 制作时间(分钟)
    servings: number  // 适合人数
    ingredients: string  // 食材清单
    instructions: string  // 制作步骤
    tips: string  // 小贴士
    user_id: number
    family_id: number
    created_at: string
    updated_at: string
}

// 食谱查询参数
export interface RecipeQuery extends PageQuery {
    name?: string
    type?: string
    difficulty?: number
}

// 创建食谱请求参数
export interface CreateRecipeRequest {
    name: string
    type: string
    difficulty: number
    cooking_time: number
    servings: number
    ingredients?: string
    instructions?: string
    tips?: string
    user_id: number
    family_id: number
}

// 更新食谱请求参数
export interface UpdateRecipeRequest {
    name?: string
    type?: string
    difficulty?: number
    cooking_time?: number
    servings?: number
    ingredients?: string
    instructions?: string
    tips?: string
}

// 食谱API接口定义
export const RecipeApi = {
    // 获取食谱列表
    getRecipeList: (params: RecipeQuery) => {
        return api.get<PageData<RecipeInfo>>('/family/recipe/list', { params })
    },

    // 用户获取食谱列表
    UserGetRecipeList: (params: RecipeQuery) => {
        return api.get<PageData<RecipeInfo>>('/family/recipe/user-recipe/list', { params })
    },
    
    // 获取食谱详情
    getRecipeDetail: (id: number) => {
        return api.get<RecipeInfo>(`/family/recipe/${id}`)
    },
    
    // 创建食谱
    createRecipe: (data: CreateRecipeRequest) => {
        return api.post<RecipeInfo>('/family/recipe/create', data)
    },
    
    // 更新食谱
    updateRecipe: (id: number,  data:UpdateRecipeRequest) => {
        return api.put<RecipeInfo>(`/family/recipe/${id}`, data)
    },
    
    // 删除食谱
    deleteRecipe: (id: number) => {
        return api.delete(`/family/recipe/${id}`)
    }
}